#!/usr/bin/python3
# -*- coding: utf-8 -*-

from fastapi import Header, UploadFile
from pydantic import BaseModel, Field
from app import app

@app.get("/query_params", summary="查询字符串参数Demo")
def with_query_params(name: str, age: int):
    return {"name": name, "age": age}


@app.get("/user/{user_id}/path_params", summary="路径参数Demo")
def with_path_params(user_id: int):
    return {"user_id": user_id}


class UserLoginIn(BaseModel):
    account: str = Field(..., description="账号")
    password: str = Field(..., description="密码")


@app.post("/user/login/json_params", summary="json参数demo")
def with_json_params(req_model: UserLoginIn):
    return req_model.model_dump()


@app.get("/user/detail/header_params", summary="请求头参数demo")
def with_header_params(
        token: str = Header(description="访问token"),
        user_agent: str = Header(description="用户代理")
):
    return {"token": token, "User-Agent": user_agent}


@app.post("/file_upload/file_params", summary="文件参数demo")
async def with_file_params(file: UploadFile):
    return {"filename": file.filename, "file_size": file.size}


@app.get("/users/{user_id}/path_query_params", summary="路径参数+查询字符串参数demo")
def with_path_query_params(user_id: int, age: int = None):
    return {"user_id": user_id, "age": age}
